<?php

namespace App\Http\Controllers\Order;

use App\Http\Controllers\BaseController;
use App\Models\Order\Saleorderfee;
use Illuminate\Http\Request;

/**
 * 其他费用模块
 */
class SaleorderfeeController extends BaseController
{
    /**
     * 详情
     */
//    public function getone(Request $request)
//    {
//        $order_number = $request->order_number ?? 0;
//        $subQuery = Saleorderfee::selectRaw('MAX(id) as max_id, other_pid')
//            ->where('order_number', $order_number)
//            ->groupBy('other_pid');
//
//        $list = Saleorderfee::joinSub($subQuery, 'latest', function ($join) {
//                $join->on('id', '=', 'latest.max_id');
//            })
//            ->get();
//
//        if (!$list) {
//            return response()->json(['code' => '001', 'msg' => '订单不存在']);
//        }
//        $list = $list->toArray();
//        if ($list) foreach ($list as $key => $value) {
//            $list[$key]['price'] = mathfuncmoney('div', $value['price'], 100, 2);
//        }
//        return response()->json(['code' => '000', 'msg' => '操作成功', 'data' => $list]);
//    }

    public function getone(Request $request)
    {
        $sales_id = $request->id ?? 0;
        $subQuery = Saleorderfee::selectRaw('MAX(id) as max_id, other_pid')
            ->where('sales_id', $sales_id)
            ->groupBy('other_pid');

        $list = Saleorderfee::joinSub($subQuery, 'latest', function ($join) {
                $join->on('id', '=', 'latest.max_id');
            })
            ->get();

        if (!$list) {
            return response()->json(['code' => '001', 'msg' => '订单不存在']);
        }
        $list = $list->toArray();
        if ($list) foreach ($list as $key => $value) {
            $list[$key]['price'] = mathfuncmoney('div', $value['price'], 100, 2);
        }
        return response()->json(['code' => '000', 'msg' => '操作成功', 'data' => $list]);
    }
}
